#include <stddef.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

#include "src/config/config.h"
#include "rinit/controller.h"
#include "log/logm.h"



int main(int argc,char **argv){
   char filename[30];
   split_dir_file(NULL,filename,argv[0]);
   //trim(filename);
   if (strcmp(filename,"init")==0)
   {
      run();
   }else if (strcmp(filename,"logm")==0)
   {
      logm_server();
   }else if (strcmp(filename,"systemctl")==0)
   {
      if (argc==2)
      {
         client("/run/rinitd/rinitd.sock",argv[1],NULL);
      }else if (argc==3)
      {
         client("/run/rinitd/rinitd.sock",argv[1],argv[2]);
      }else{
         printf("%s\n","[\033[3;32mrinitd\033[0m] version 0.1.0\n\nbuiltin binary: [\033[3;32minit,logm,systemctl,shutdown\033[0m]");
         return 0;  
      } 
   }else if (strcmp(filename,"shutdown")==0)
   {
      if (argc==1)
      {
          client("/run/rinitd/rinitd.sock","shutdown",NULL);
      }else{
         printf("%s\n","[\033[3;32mrinitd\033[0m] version 0.1.0\n\nbuiltin binary: [\033[3;32minit,logm,systemctl,shutdown\033[0m]");
         return 0; 
      }
      
   }else{
      printf("%s\n","[\033[3;32mrinitd\033[0m] version 0.1.0\nbuiltin binary:\n     [\033[3;32minit,logm,systemctl,shutdown\033[0m]");
   }
   
   return 0;
}
